#include <pspkernel.h>
#include "../Common/Callbacks.h"
#include "../Epik_Controller.h"

PSP_MODULE_INFO("Epik_Controller DEMO", 0, 1, 1);

int main()
{
	SetupCallbacks();
	pspDebugScreenInit();

	bool btnSTART;
	bool btnX, btnO, btnSq, btnTr;
	bool padU, padD, padL, padR;

	Epik_Controller *ec = new Epik_Controller(&_running);
	ec->BindButton(Epik_Controller::HUB_START, &btnSTART);

	ec->BindButton(Epik_Controller::BTN_CROSS, &btnX);
	ec->BindButton(Epik_Controller::BTN_CIRCLE, &btnO);
	ec->BindButton(Epik_Controller::BTN_SQUARE, &btnSq);
	ec->BindButton(Epik_Controller::BTN_TRIANGLE, &btnTr);
	ec->BindButton(Epik_Controller::DPAD_UP, &padU);
	ec->BindButton(Epik_Controller::DPAD_DOWN, &padD);
	ec->BindButton(Epik_Controller::DPAD_LEFT, &padL);
	ec->BindButton(Epik_Controller::DPAD_RIGHT, &padR);

	pspDebugScreenClear();
	pspDebugScreenSetTextColor(0x0000FF);
	pspDebugScreenPrintf("Epik_Controller DEMO\n");
	pspDebugScreenSetTextColor(0xFF0000);
	pspDebugScreenPrintf("   This program demonstrates the response of button input.\n");
	pspDebugScreenPrintf("   Use the D-Pad or X,O,^ and # buttons to test the events.\n");
	pspDebugScreenSetTextColor(0xFFFFFF);
	pspDebugScreenPrintf(" START -> Quit program;\n");
	pspDebugScreenPrintf("\n");
	pspDebugScreenSetTextColor(0x888888);
	pspDebugScreenPrintf("  /---\\    /---\\ \n");
	pspDebugScreenPrintf(" /     \\  /     \\\n");
	pspDebugScreenPrintf(" |     |  |     |\n");
	pspDebugScreenPrintf(" \\     /  \\     /\n");
	pspDebugScreenPrintf("  \\---/    \\---/ \n");

	while(_running)
	{
		ec->UpdateButtons();

		pspDebugScreenPutChar(29,48,(padU)?0xEEEEEE:0,'^');
		pspDebugScreenPutChar(21,56,(padL)?0xEEEEEE:0,'<');
		pspDebugScreenPutChar(37,56,(padR)?0xEEEEEE:0,'>');
		pspDebugScreenPutChar(29,64,(padD)?0xEEEEEE:0,'v');

		pspDebugScreenPutChar(91,48,(btnTr)?0x00FF00:0,'^');
		pspDebugScreenPutChar(84,56,(btnSq)?0xFF8888:0,'#');
		pspDebugScreenPutChar(100,56,(btnO)?0xFF0000:0,'O');
		pspDebugScreenPutChar(92,64,(btnX)?0x0000FF:0,'X');

		if (btnSTART)
			_running = false;
	}

	sceKernelExitGame();
}

